#include <algorithm>
#include <iostream>
using namespace std;

struct node {
    int x, y;
};

node a[100007];
bool cmp(node A, node B) {
    if (A.x == B.x)
        return A.y < B.y;
    else
        return A.x < B.x;
}

int solution(string& S) {
    int n = S.size();
    for (int i = 0; i < n; ++i) {
        a[i + 1].x = a[i].x ^ (1 << (S[i] - 'a'));
        a[i + 1].y = i + 1;
    }
    sort(a + 0, a + n + 1, cmp);
    int beg = 0, ans = 0;
    for (int i = 1; i <= n; ++i) {
        if (a[i].x != a[i - 1].x) { beg = i; }
        if (i != beg) ans = max(ans, a[i].y - a[beg].y);
    }
    return ans;
}